<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>代理商维护</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <link rel="stylesheet" type="text/css" href="/js/uploadify-v3.2.1/uploadify.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script type="text/javascript" src="/js/uploadify-v3.2.1/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="/js/uploadUtil.js"></script>
</head>

<body class="easyui-layout" style="padding:5px">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>统一社会信用代码：</th>
                    <td style="width:120px"><input  id="searchType" class="textbox" name="type" value="1" type="hidden"/>
                        <input name="socialCode" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司名称：</th>
                    <td style="width:120px">
                        <input name="name" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司地址：</th>
                    <td style="width:120px">
                        <input name="address" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <!--<th>公司类型：</th>
                    <td style="width:120px">
                        <select id="typeSelect" name="type" class="easyui-combobox" data-options="onSelect: function(rec){onSearch()}" style="width:100px">
                            <option value="-1">全部</option>
                            &lt;!&ndash;<option value="0">平台公司</option>&ndash;&gt;
                            <option value="1">代理商</option>
                            <option value="2">合作伙伴</option>
                        </select>
                    </td>-->
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"> </table>

<div id="addOrEdit" class="easyui-window" title="添加代理商" data-options="closed:true,iconCls:'icon-save',footer:'#ft'" style="width:600px;height:600px;padding:10px;">
    <form id="ff" method="post">
        <table class="table-blue">
            <tr>
                <th>公司类型：</th>
                <td><input id = "addType" name="type"  value="1" type="hidden"/>
                    <input disabled="true" id="addTypeName" class="textbox" value="代理商" data-options="required:true, validType:'maxLength[50]'"/>
                </td>
            </tr>
            <tr>
                <th>公司名称：</th>
                <td><input type="hidden" name="id"/><input class="easyui-validatebox textbox" type="text" name="name" data-options="required:true, validType:'maxLength[50]'"/>
                </td>
            </tr>
            <tr>
                <th>统一社会信用代码：</th>
                <td><input type="hidden" name="leader"/><input class="easyui-validatebox textbox" type="text" name="socialCode" data-options="required:true, validType:'maxLength[18]'"/>
                </td>
            </tr>
            <tr>
                <th>公司地址：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="address" data-options="required:true, validType:'maxLength[18]'"/>
                </td>
            </tr>
            <tr>
                <th>负责人：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="leaderName" data-options="required:true, validType:'maxLength[30]'"/></td>
            </tr>
            <tr>
                <th>手机号：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="mobile" data-options="required:true, validType:['mobile','maxLength[11]']"/></td>
            </tr>
            <tr>
                <th>邮箱：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="email" data-options="prompt:'Enter a valid email.',validType:['email','maxLength[45]']"/></td>
            </tr>
            <tr>
                <th>银行卡号：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="bankCardNumber" data-options="required:true,validType:['maxLength[50]']"/></td>
            </tr>
            <tr>
                <th>支付宝账号：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="alipayAccount" data-options="validType:['maxLength[19]']"/></td>
            </tr>
            <tr>
                <th>微信账号：</th>
                <td><input class="easyui-validatebox textbox" type="text" name="wechatAccount" data-options="validType:['maxLength[50]']"/></td>
            </tr>
            <!-- <tr>
                 <th>营业执照：</th>
                 <td><input class="easyui-validatebox textbox" type="text" name="businessLicense" data-options="validType:['maxLength[50]']"/></td>
             </tr>-->
            <tr>
                <th style="vertical-align: middle;padding-top: 10px;">营业执照：</th>
                <td class="inputTd" >
                    <div style="float: left;">
                        <input type="hidden" name="licensePath" id="licensePath" value=""/>
                        <img alt="" src="/images/default.jpg" width="200" height="100" id="staticInfoImageShow">
                        <br>
                        <div style="float:left;margin-right: 40px">
                            <input type="file" name="staticInfoImage" id="staticInfoImage" />
                        </div>
                        <div class="uploadify-button " id="deleteStaticInfoImageBtn" onclick="deleteStaticInfoImg();" style="line-height: 22px; width: 80px; height: 22px;cursor:pointer;float: left;display:none">
                        <span class="uploadify-button-text">
						删除图片
						</span>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <th style="vertical-align: middle;padding-top: 10px;">合作协议：</th>
                <td class="inputTd" >
                    <input type="hidden" name="agreementPath" id="agreementPath" value=""/>
                    <input type="hidden" name="agreementName" id="agreementName" value=""/>
                    <div style="margin-bottom:20px;display:none" id="fileDivid">
                        <!--<input class="easyui-filebox" name="agreementfile" id="agreementfile" data-options="prompt:'请选择协议'" style="width:70%">-->
                        <input type="file" name="agreementfile" id="agreementfile" data-options="prompt:'请选择协议'" onchange="uploadAgreementFile(this)"/>
                       <!-- <input type="button" id="upload" value="上传" onclick="uploadAgreementFile()"/>-->
                    </div>
                    <div style="margin-bottom:20px;display:none" id="downDivid">

                    </div>
                </td>
            </tr>
            <!-- <tr>
                 <th>备注：</th>
                 <td><input class="easyui-validatebox textbox" name="remark" data-options="multiline:true, validType:'maxLength[60]'" style="height:60px;"/></td>
             </tr>-->
        </table>
    </form>
    <div id="ft" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="submitForm()"
           style="width:80px">Ok</a> &nbsp;&nbsp;
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)"
           onclick="closeWindow()" style="width:80px">Cancel</a>
    </div>
</div>

<!--绑定设备-->
<div id="bindeEquipment" class="easyui-window" title="绑定设备"
     data-options="closed:true,iconCls:'icon-save',footer:'#equipmentFTL'"
     style="width:600px;height:400px;padding:10px;">
    <div id="equipmentSerach">
        <form id="consoleSearch">
            <input id="ss" name="machineCode" class="easyui-searchbox" style="width:300px"
                   data-options="searcher:onConsoleSearch,prompt:'模糊查询机器码'"></input>
            <input type="hidden" name="agentId" id="agentIdSearch">
        </form>
    </div>
    <div id="equipmentDL" height="95%" ></div>
    <div id="equipmentFTL" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="bindConsule();"
           style="width:80px">Ok</a> &nbsp;&nbsp;
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)"
           onclick="closeWindow()" style="width:80px">Cancel</a>
    </div>
</div>

<div id="showImageId" class="easyui-window" title="营业执照" data-options="closed:true" style="width:600px;height:400px;padding:10px;">
    <div style="float: left;">
        <img alt="" src="/images/default.jpg" width="100%" height="100%" id="showCompanyImageId">
    </div>
</div>
<!--使用的费率设置-->
<div id="bindRate" class="easyui-window" title="费率设置" data-options="closed:true,iconCls:'icon-save',footer:'#rateFTL'"
     style="width:400px;height:300px;padding:10px;">
    <div id="rateDL">
        <form  id="rateFF">
            <table class="table-blue">
                <tr>
                    <th>平台使用费率：</th>
                    <td>
                        <input id = "rateId" name="id"  type="hidden" >
                        <input id = "agentId" name="agentId"  type="hidden">
                        <input id = "platformRate" name = "platformRate" class="easyui-validatebox textbox" type="text" onblur="checkNumber(this.value);"  placeholder="请输入正数" ><span>%</span>
                    </td>
                </tr>
                <tr>
                    <th>服务保障金费率：</th>
                    <td>
                        <input id = "serviceGuarantee" name = "serviceGuarantee" class="easyui-validatebox textbox" type="text" onblur="checkNumber(this.value);" placeholder="请输入正数"><span>%</span>
                    </td>
                </tr>
                <tr>
                    <th>网间账户额度：</th>
                    <td>
                        <input id = "internetAccount" name = "internetAccount" class="easyui-validatebox textbox" type="text" onblur="checkNumber(this.value);" placeholder="请输入正数"><span>元</span>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="rateFTL" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="bindRate()"
           style="width:80px">Ok</a> &nbsp;&nbsp;
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)"
           onclick="closeWindow()" style="width:80px">Cancel</a>
    </div>
</div>


<div id="showDetail"  class="easyui-window" style="width:70%;height:73%;padding:10px;" title="查看详情" data-options="closed:true,iconCls:'icon-save'">
    <div id="detail" >
        <table id="detail_table" class="table-blue"  style="width:98%" >
            <tr style="height:30px;">
                <th>公司名称：</th><td align="center"><span id="detail_name"></span></td><th style="width:15%">统一社会信用代码：</th><td align="center"><span id="detail_socialCode">null</span></td>
            </tr>
            <tr style="height:30px;">
                <th>公司地址：</th><td align="center"><span id="detail_address"></span></td><th>公司责任人名称：</th><td align="center"><span id="detail_leaderName">null</span></td>
            </tr>
            <tr style="height:30px;">
                <th>公司电话：</th><td align="center"><span id="detail_mobile"></span></td><th>公司邮箱：</th><td align="center"><span id="detail_email">null</span></td>
            </tr>
            <tr style="height:30px;">
                <th>银行卡号：</th><td align="center"><span id="detail_bankCardNumber"></span></td><th>支付宝账号：</th><td align="center"><span id="detail_alipayAccount">null</span></td>
            </tr>
            <tr style="height:30px;">
                <th>微信账号：</th><td align="center"><span id="detail_wechatAccount"></span></td><th>创建时间：</th><td align="center"><span id="detail_createTime">null</span></td>
            </tr>
            <!--<tr style="height:30px;">-->
                <!--<th>备注：</th><td colspan="3"><span id="detail_remark"></span></td>-->
            <!--</tr>-->
            <tr >
                <th>营业执照：</th><td colspan="3" align="center">
                <div style="width:90%;height:340px">
                    <img alt="" src="/images/default.jpg" width="90%" id="detail_license" style="height:340px">
                </div>
            </td>
            </tr>
        </table>
    </div>
    <div id="detail_close" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="closeWindow()" style="width:80px">Close</a>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        var dg = $('#dg').datagrid();
        var queryParams = $('#ffSearch').serializeObject();
        var companyBindConsole;
        dg.datagrid({
            url:'/v1/api0/company/list',
            queryParams: queryParams,
            columns:[[
                {field:'id',checkbox:true},
                {field:'name',title:'公司名称',width:100},
                {field:'socialCode',title:'统一社会信用代码',width:100,
               formatter:function (value, row, index) {
                 return '<a href="#" onclick="showRowImg(' + index + ')">'+row.socialCode+'</a>';
                }},
                {field:'leader',title:'负责人ID',hidden:true},
                {field:'leaderName',title:'负责人名称',width:100},
                {field:'mobile',title:'手机号',width:100},
                {field:'type',title:'类型',hidden:true},
                {field:'email',title:'邮箱',width:100},
                {field:'agreementName',title:'合作协议',width:100,formatter: function(value,row,index){
                if(row.agreementName!='null'&&row.agreementName!=null&&row.agreementName!='undefined'&&row.agreementPath!='null'&&row.agreementPath!=null&&row.agreementPath!='undefined'){
                    return  '<a href='+serverPath+'/GetFile?fn='+row.agreementName+'&bt=informationFile&pt='+row.agreementPath+'>'+row.agreementName+'</a>';
                    }
                }},
                {field:'address',title:'公司地址',width:100},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'action',title:'操作',width:120,formatter: function(value,row,index){
                    if(row.status == 1){
                        return  '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="disable(\''+row.id+'\',\''+row.leader+'\')">禁用</a> | ' +
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="detail(\''+row.id+'\')">查看详情</a> | ' +
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showBindRate(\''+row.id+'\')">费率设置</a> | ' +
                            '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showBindConsule(\''+row.id+'\')">设备绑定</a>';
                    }else{
                        return  '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="enable(\''+row.id+'\',\''+row.leader+'\')">启用</a>   | ' +
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="detail(\''+row.id+'\')">查看详情</a> | ' +
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showBindRate(\''+row.id+'\')">费率设置</a> | ' +
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showBindConsule(\''+row.id+'\')">设备绑定</a>';
                    }
                }}
            ]],
            title:'代理商管理',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: false,
            toolbar: [{
                id: 'btnAdd',
                text: '添加',
                iconCls: 'icon-add',
                handler: function () {
                    add();
                }
            }, '-', {
                id: 'btnEdit',
                text: '修改',
                iconCls: 'icon-edit',
                handler: function () {
                    edit();
                }
            }, '-', {
                id: 'btnDisable',
                text: '禁用',
                iconCls: 'icon-remove',
                handler: function () {
                    batchDisable();
                }
            }, '-', {
                id: 'btnEnable',
                text: '启用',
                iconCls: 'icon-add',
                handler: function () {
                    batchEnable();
                }
            },  '-', {
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }]
        });


        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url:'/v1/api0/company/list',
            queryParams: queryParams
        });
    }
    //绑定设备搜索框
    function onConsoleSearch(){
     var queryParams = $('#consoleSearch').serializeObject();
     $('#equipmentDL').datagrid({
     url:'/v1/api0/equipment/AgentconsoleList',
     queryParams: queryParams
      });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
         $("#searchType").val("1");//查询默认值保持代理商
        onSearch();
    }

    function add() {
        $('#ff').form('clear');
        $("#addType").val("1");//类型为代理商类型1，隐藏。
        $("#addTypeName").val("代理商");//类型为代理商，显示。
         deleteStaticInfoImg();
         getshowFile("","","");
        $("#ff input[name='id']").val("");
        $('#addOrEdit').window({title:'添加公司'});
        $('#addOrEdit').window('open');
    }

    function edit() {
        $('#ff').form('clear');
        $("#addType").val("1");//类型为代理商类型1，隐藏。
        $("#addTypeName").val("代理商");//类型为代理商，显示。
        var row = $('#dg').datagrid('getSelected');
        if (!row){
            top.window.showMessage("请选择公司");
            return;
        }
         getupdateImg(row.licensePath);
         getshowFile(row.agreementPath,row.agreementName,row.id);
        $('#ff').form('load',row);
        $("#ff input[name='id']").val(row.id);
        $('body').data('ff-serialize', $('#ff').serialize());
        $('#addOrEdit').window({title:'编辑公司'});
        $('#addOrEdit').window('open');
    }

    function submitForm(){
        var id = $("#ff input[name='id']").val();
        var url = id.length ? "/v1/api0/company/edit" : "/v1/api0/company/add";
        var data = $('#ff').serialize();
        if(data == $('body').data('ff-serialize')) {
            top.window.showMessage("数据没有改动");
            return;
        }
        $.ajax({
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                if (!$('#ff').form('validate')){
                    return false;
                }
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if(data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        });
    }

    function closeWindow(){
        $('#bindeEquipment').window('close');
        $('#addOrEdit').window('close');
        $('#bindRate').window('close')
        $('#showDetail').window('close');;
    }

    function batchDisable() {
        var ids = [];
        var leaders = [];
        var rows = $('#dg').datagrid('getSelections');
        if(!rows.length) {
            top.window.showMessage("请选择公司");
            return;
        }
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].id);
            leaders.push(rows[i].leader);
        }

        top.window.$.messager.confirm('确认', '您确定要禁用选择的公司吗？', function(r){
            if (r){
                var url = "/v1/api0/company/batchDisable";
                var data = {ids: ids.join(','),leaders:leaders.join(',')};
                $.ajax(ajaxOption(url, data));
            }
        });
    }

    function batchEnable() {
        var ids = [];
        var leaders = [];
        var rows = $('#dg').datagrid('getSelections');
        if(!rows.length) {
            top.window.showMessage("请选择公司");
            return;
        }
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].id);
            leaders.push(rows[i].leader);
        }

        top.window.$.messager.confirm('确认', '您确定要启用选择的公司吗？', function(r){
            if (r){
                var url = "/v1/api0/company/batchEnable";
                var data = {ids: ids.join(','),leaders:leaders.join(',')};
                $.ajax(ajaxOption(url, data));
            }
        });
    }

    function disable(id,leader) {
     top.window.$.messager.confirm('确认', '您确定要禁用该公司吗？', function(r){
            if (r){
               var url = "/v1/api0/company/disable";
            var data = {id: id,leader:leader};
            $.ajax(ajaxOption(url, data));
            }
        });
    }

    function enable(id,leader) {
    top.window.$.messager.confirm('确认', '您确定要启用该公司吗？', function(r){
            if (r){
               var url = "/v1/api0/company/enable";
        var data = {id: id,leader:leader};
        $.ajax(ajaxOption(url, data));
            }
        });
    }

    function ajaxOption(url, data) {
        return {
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if(data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        }
    }

    function showBindConsule(companyID){
    companyBindConsole = companyID;
    queryParams={agentId:companyID};
    $('#agentIdSearch').val(companyID);
        $('#equipmentDL').datagrid({
            url: '/v1/api0/equipment/AgentconsoleList',
            singleSelect: false,
            rownumbers: false,
            queryParams: queryParams,
            pagination: true,
            columns:[[
                {field:'id',checkbox:true},
                {field:'machineCode',title:'机器码',width:100},
                {field:'businessCode',title:'业务码',width:100},
                {field:'agentId',title:'代理商ID',hidden:true},
                {field:'remarks',title:'备注',width:100},
                {field:'createTime',title:'创建时间',width:100,formatter: formatDateTime}
            ]],onLoadSuccess:function(row) {
                var rowData = row.rows;
                $.each(rowData, function(idx,val){//遍历JSON
                      if(val.agentId!= null&&val.agentId!='null'&&val.agentId!='undefined'){
                      $("#equipmentDL").datagrid("selectRow", idx);//如果数据行为已选中则选中改行
                      return;
                      }
                });
            }
        });
        $('#bindeEquipment').window('open');
    }
    function bindConsule(){
        var consoleIds = [];
        var companyId = companyBindConsole;
        var rows = $('#equipmentDL').datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            consoleIds.push(rows[i].id);
        }
        top.window.$.messager.confirm('确认', '请确认您的选择', function(r){
            if (r){
                var url = "/v1/api0/equipment/AgentBindConsole";
                var data = {consoleIds: consoleIds.join(','),companyID:companyId};
                $.ajax({
                type: "post",
                url: url,
                data: data,
                datatype: "json",
                success: function (data) {
                if(data.code == 200) {
                    $('#equipmentDL').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#equipmentDL').datagrid('loaded');
                }
            },
            error: function () {
                $('#equipmentDL').datagrid('loaded');
            }
                });
            }
        });
    }


var staticInfoImgObj={
		"uploadId":"staticInfoImage",
		"uploadType":"staticInfoImage",
		"buttonType":"text",//按钮类型  img或text
		"buttonText":"选择图片",//如果按钮类型为‘text’,则配置需要 显示的文本按钮显示内容
		"fileObjName":"Filedata",//传递到后台的参数名称
		"fileSizeLimit":"1MB",//上传文件的大小限制 ，如果为整数型则表示以KB为单位的大小，如果是字符串，则可以使用(B, KB, MB, or GB)为单位，比如’2MB’
		"fileTypeExts":"*.jpg;*.png;*.jpge;*.gif",//可上传文件类型限制
		"uploadImgMethod":"staticInfoImgSuccess"//上传完成后回调名，会给回调方法传递fileObj
		};
createUploadify(staticInfoImgObj);
function staticInfoImgSuccess(serverDate){
	$("#staticInfoImageShow").attr("src",serverDate.resultMap.imageUrl);
	$("#staticInfoImage").val(serverDate.resultMap.fileNameNew);
	$("#licensePath").val(serverDate.resultMap.fileNameNew);
	$("#deleteStaticInfoImageBtn").show();
	return;
}
function deleteStaticInfoImg(){
	$("#staticInfoImageShow").attr("src","/images/default.jpg");
	$("#staticInfoImage").val("");
	$("#licensePath").val("");
	$("#deleteStaticInfoImageBtn").hide();
}
function getupdateImg(imgname){
   if(imgname!=""&&imgname!=null&&imgname!=undefined){
    $("#staticInfoImageShow").attr("src",serverPath+"/GetImage?bt=staticInfoImage&fn="+imgname);
	$("#staticInfoImage").val(imgname);
	$("#licensePath").val(imgname);
	$("#deleteStaticInfoImageBtn").show();
   }else{
   deleteStaticInfoImg();
   }
}
function showRowImg(img){
  $('#dg').datagrid('selectRow', img);
  var row = $('#dg').datagrid('getSelected');
  var imgpath=row.licensePath;
  if(imgpath!=""&&imgpath!=null&&imgpath!=undefined){
  $("#showCompanyImageId").attr("src",serverPath+"/GetImage?bt=staticInfoImage&fn="+imgpath);
  $('#showImageId').window('open');
   }else{
   top.window.showMessage("该公司还未上传营业执照！");
   }
}


    //显示绑定费率设置
    function showBindRate(companyID){
    $('#rateFF').form('clear');
    var url = "/v1/api0/company/getAgentRate";
    var data = {companyId: companyID};
    $.ajax({
                type: "post",
                url: url,
                data: data,
                datatype: "json",
                success: function (data) {
                if(data.code == 200) {
                    var rate = data.body;
                    if(rate!='null'&&rate!=null&&rate!='undefined'){
                    $('#rateFF').form('load',rate);
                    $("#rateFF input[name='id']").val(rate.id);
                    }
                    $("#rateFF input[name='agentId']").val(companyID);
                    $('body').data('rateFF-serialize', $('#rateFF').serialize());
                } else {
                     top.window.showMessage(data.msg);
                }
            },
            error: function () {
                top.window.showMessage("查询费率设置失败！");
            }
    });
        $('#bindRate').window('open');
    }

    //绑定费率设置
    function bindRate(){

        var url = "/v1/api0/company/bindAgentRate";
        var data = $('#rateFF').serialize();
        if(data == $('body').data('rateFF-serialize')) {
            top.window.showMessage("数据没有改动");
            return;
        }
        $.ajax({
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                if (!$('#rateFF').form('validate')){
                    return false;
                }
            },
            success: function (data) {
                if(data.code == 200) {
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                }
            },
            error: function () {
                 top.window.showMessage("保存时连接失败！");
            }
        });
    }

function getshowFile(agreementPath,agreementName,companyId){
   if(agreementPath!=""&&agreementPath!=null&&agreementPath!=undefined){
   <!--<a href="#" onclick=downLoadFile("42ad14ec-2285-4fc0-befd-39834627423a.pdf","后台管理系统.pdf")>后台管理系统.pdf</a>-->
   <!--<a href="javascript:void(0)" class="easyui-linkbutton" onclick="disable(\''+row.id+'\',\''+row.leader+'\')">禁用</a>-->
    $("#fileDivid").hide();
    $("#downDivid").show();
    var businessType="informationFile";
    $("#downDivid").html('<a href='+serverPath+'/GetFile?fn='+agreementName+'&bt='+businessType+'&pt='+agreementPath+'>'+agreementName+'</a> <input type="button" id="deletFileid" value="刪除" onclick="deletAgreementFile(\''+agreementPath+'\',\''+agreementName+'\',\''+companyId+'\')"/>');
    <!--$("#downDivid").html('');-->
    $("#agreementPath").val(agreementPath);
    $("#agreementName").val(agreementName);
    }else{
    $("#downDivid").hide();
    $("#fileDivid").show();
    $("#agreementPath").val("");
    $("#agreementName").val("");
    }
}
function isIE() {
    if (!!window.ActiveXObject || "ActiveXObject" in window){
        return true;
        }else {
        return false;
        }
}
function uploadAgreementFile(target){
 var fileSize = 0;
     if (isIE && !target.files) {
      var filePath = target.value;
      var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
      var file = fileSystem.GetFile (filePath);
      fileSize = file.Size;
    } else {
     fileSize = target.files[0].size;
     }
     var size = fileSize / 1024;
     if(size>1000){
      top.window.showMessage("附件不能大于1M!");
      target.value="";
      return;
     }
     var name=target.value;
     var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
     if(fileName !="doc" && fileName !="docx" && fileName !="pdf" && fileName !="txt" && fileName !="xls" && fileName !="xlsx"){
        top.window.showMessage("附件格式只支持.doc;.docx;.pdf;.txt;.xls.;xlsx!");
         target.value="";
         return ;
     }else{
 var formData = new FormData();
 formData.append("agreementfile", $('#agreementfile')[0].files[0]);
  $.ajax({
                    url: "/v1/api0/upload",
                    type: "POST",
                    data: formData,
                    /**
                    *必须false才会自动加上正确的Content-Type
                    */
                    contentType: false,
                    /**
                    * 必须false才会避开jQuery对 formdata 的默认处理
                    * XMLHttpRequest会对 formdata 进行正确的处理
                    */
                    processData: false,
                    success: function (data) {
                     if(data.code == 200) {
                       $("#upload").attr("disabled","disabled");
                       var agreementName=data.msg.split("_")[0];
                       var agreementPath=data.msg.split("_")[1];
                     $("#agreementName").val(agreementName);
                     $("#agreementPath").val(agreementPath);
                     top.window.showMessage("附件上传成功！");
                    } else {
                    $("#upload").removeAttr("disabled");
                    top.window.showMessage(data.msg);
                    }
                    },
                    error: function () {
                    $("#upload").removeAttr("disabled");
                    top.window.showMessage("附件上传失败");
                    }
                });
          }
}

function deletAgreementFile(agreementPath,agreementName,companyId){
 $.ajax({
                    url: "/v1/api0/deletAgreementFile",
                    type: "POST",
                    dataType:"json",
                    data:{"agreementPath":agreementPath,"agreementName":agreementName,"companyId":companyId},
                    async:false,
                    success: function (data) {
                    if(data.code == 200) {
                    $("#downDivid").hide();
                    $("#fileDivid").show();
                     $("#agreementName").val("");
                     $("#agreementPath").val("");
                     top.window.showMessage("附件删除成功！");
                    } else {
                     $("#fileDivid").hide();
                     $("#downDivid").show();
                     $("#agreementName").val(agreementName);
                     $("#agreementPath").val(agreementPath);
                    top.window.showMessage(data.msg);
                    }
                    },
                    error: function () {
                     $("#fileDivid").hide();
                     $("#downDivid").show();
                     $("#agreementName").val(agreementName);
                     $("#agreementPath").val(agreementPath);
                    top.window.showMessage("附件删除失败！");
                    }
                });
}


function checkNumber(input) {
 　　var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/
　　if (!re.test(input)) {
 　　　　alert("请输入正整数");
 　　　　return false;
 　　}else{
            return true;
        }
 }
 function detail(comID){
    $.ajax({
    method:"post",
    url:'/v1/api0/company/detail',
    data:{companyID:comID},
    success:function(data){
        var company = data.body;
        $('#detail_name').text(company.name);
        $('#detail_socialCode').text(company.socialCode);
        $('#detail_address').text(company.address);
        $('#detail_leaderName').text(company.leaderName);
        $('#detail_mobile').text(company.mobile);
        $('#detail_email').text(company.email);
        $('#detail_bankCardNumber').text(company.bankCardNumber);
        $('#detail_alipayAccount').text(company.alipayAccount);
        $('#detail_wechatAccount').text(company.wechatAccount);
        <!--$('#detail_remark').text(company.remarks);-->
        $("#detail_license").attr("src",serverPath+"/GetImage?bt=staticInfoImage&fn="+company.licensePath);
        var createtime = company.createTime;
        createtime = new Date(createtime);
        var year = createtime.getFullYear()+'年';
        var month = createtime.getMonth()+1+'月';
        var date = createtime.getDate()+'日';
        $('#detail_createTime').text([year,month,date].join('-'));
    }
    });
$('#showDetail').window('open');
}

</script>
</body>
</html>
